#ifndef THUNDERRAID_FADESTACKWIDGET_H
#define THUNDERRAID_FADESTACKWIDGET_H

#include <QStackedWidget>
#include <QVariant>

class QVariantAnimation;

class FadeStackWidget : public QStackedWidget{
    Q_OBJECT
public:
    explicit FadeStackWidget(QWidget *parent = nullptr);

    void switchTo(int index);
    void switchTo(QWidget *widget);

signals:
    void changeFinished();

protected:
    void paintEvent(QPaintEvent *event) override;

private:
    void paintWidget(QPainter *painter, QWidget *source, qreal opacity);

private slots:
    void onValueChange(const QVariant &value);
    void onAnimationFinished();

private:
    QVariantAnimation *animation; //动画框架
    int default_duration;                  //动画的持续时间
    QVariant currentValue{};   //被Animation动画改变的值
    QWidget *next_widget = nullptr;
};


#endif//THUNDERRAID_FADESTACKWIDGET_H
